import {message} from 'antd';
import { reqUploadFile,reqGetHeader,reqGetList } from './server';

export const models = {
  name: 'mitrixManage',
  model: {
    state: {
      headerList:[],
      loadingHeader:true,
      list:[],
      loadingList:true
    },
    reducers: { 
      setHeader(state,payload) {
        return {...state,headerList:payload,loadingHeader:false}
      },
      setList(state,payload) {
        return {...state,list:payload,loadingList:false}
      },
    },
    effects: dispatch => {
      return {
        async uploadFile(params) {
          const {code, msg} = await reqUploadFile(params);
          if(code == 0) {
            message.success('上传成功');
          } else {
            message.error(msg);
          }
        },
        async getHeader(params) {
          const {code, data,msg} = await reqGetHeader(params);
          
          if(code == 0) {
            dispatch.mitrixManage.setHeader(data);
          } else {
            message.error(msg);
          }
        },
        async getList(params) {
          const {code, data,msg} = await reqGetList(params);
          
          if(code == 0) {
            dispatch.mitrixManage.setList(data);
          } else {
            message.error(msg);
          }
        }
      }
    }
  }
}